VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "NCMethodFixture"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True

'
'Copyright (c) 2010 Andrew Wall
'
' http://www.opensource.org/licenses/mit-license.php
'
'Permission is hereby granted, free of charge, to any person obtaining a copy
'of this software and associated documentation files (the "Software"), to deal
'in the Software without restriction, including without limitation the rights
'to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
'copies of the Software, and to permit persons to whom the Software is
'furnished to do so, subject to the following conditions:
'
'The above copyright notice and this permission notice shall be included in
'all copies or substantial portions of the Software.
'
'THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
'IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
'FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
'AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
'LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
'OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
'THE SOFTWARE.
'

Option Explicit
Implements MethodFixture

Private mHolder As ObjectHolder
Private mName As String
Private mDesc As ClassDescriptor

Private mElapsedTime As Double
Private mError As Integer

Public Sub init(holder As ObjectHolder, name As String, desc As ClassDescriptor)
Set mHolder = holder
mName = name
Set mDesc = desc
End Sub


Public Sub forward(notify As Object)
notify.StartMethod Me
On Error GoTo handler
forwardFineMethods
GoTo exitMethod

handler:
'Exit Sub

exitMethod:
notify.EndMethod

End Sub

Private Sub forwardFineMethods()
If mDesc.hasSetup Then setup
callMethod
If mDesc.hasTearDown Then teardown
End Sub
Private Sub setup()
Dim aTimer As New AutoTimer
aTimer.reportTo Me
'Errors raised in object are allowed to propagate up
mHolder.object.setup
End Sub
Private Sub callMethod()
Dim aTimer As New AutoTimer
aTimer.reportTo Me
On Error GoTo handler
InvokeHook mHolder.object, mName, INVOKE_FUNC
Exit Sub

handler:
'@TODO this shows that not all errors are logged!
mError = Err.Number
End Sub
Private Sub teardown()
Dim aTimer As New AutoTimer
aTimer.reportTo Me
On Error GoTo handler
mHolder.object.teardown
Exit Sub

handler:
'@TODO this shows that not all errors are logged!
mError = Err.Number
End Sub
Public Sub reportTime(elTime As Double)
mElapsedTime = mElapsedTime + elTime
End Sub


Public Property Get name() As String
name = mName
End Property
Public Property Get elapsedTime() As Double
elapsedTime = mElapsedTime
End Property

Public Property Get errorNumber() As Integer
errorNumber = mError
End Property

Private Sub MethodFixture_add(forward As Object)
Debug.Print "MethodFixture_add: " + forward.name
End Sub

Private Property Get MethodFixture_elapsedTime() As Double
MethodFixture_elapsedTime = elapsedTime
End Property

Private Property Get MethodFixture_errorCollection() As Collection

End Property

Private Sub MethodFixture_forward(notify As Object)
forward notify
End Sub

Private Sub MethodFixture_init(name As String)
Debug.Print "MethodFixture_init: " + name
End Sub

Private Property Get MethodFixture_name() As String
MethodFixture_name = name
End Property
